package com.gxr.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.lang.reflect.InvocationTargetException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.dao.ObjectDao;
import com.pro.bean.Mark;

import util.StrConvert;

public class UpdateSameServlet extends HttpServlet {

	/**
	 * ͬһ�����趨 ������°�ť �������
	 */
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		/*
		 * response.setContentType("text/html"); PrintWriter out =
		 * response.getWriter();
		 * 
		 * out.flush(); out.close();
		 */
		doPost(request, response);
	}

	/**
	 * The doPost method of the servlet. <br>
	 * 
	 * This method is called when a form has its tag value method equals to
	 * post.
	 * 
	 * @param request
	 *            the request send by the client to the server
	 * @param response
	 *            the response send by the server to the client
	 * @throws ServletException
	 *             if an error occurred
	 * @throws IOException
	 *             if an error occurred
	 */
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		response.setContentType("text/html;charset=UTF-8");
		request.setCharacterEncoding("UTF-8");
		PrintWriter out = response.getWriter();
		String name=request.getParameter("infoname");
		System.out.println("Update"+name);
		
		int count = 0;
		String arg = "mark";
		//String arg2 = "memo";
		while (request.getParameter(arg + count) != null) {
			//System.out.println(arg+count);
			int mark = Integer.parseInt(request.getParameter("mark"+count));
			String memo = (String) request.getParameter("memo"+count);
			//System.out.println("memo:"+count + memo);
			int cardid = Integer.parseInt(request.getParameter("cardid"+count));
			//System.out.println("cardid:"+count + cardid);

			Mark mk = new Mark();
			mk.setIppaternkub(mark);
			mk.setRepeatcomment(memo);
			mk.setCardid(cardid);

			ObjectDao objectDao = new ObjectDao();
			try {
				objectDao.updates(mk);
			} catch (SecurityException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (IllegalAccessException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (InvocationTargetException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (NoSuchMethodException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			
			count++;
		}
		//request.getRequestDispatcher("GetSameNameInfoServlet?name="+name).forward(request, response);
		out.println("<script>alert(\"修改成功\");location.href=\"GetSameNameInfoServlet?name="+name+"\";</script>");
		out.flush();
		out.close();
	}

}
